<template>
  <!-- 搜索页面 -->
  <div class="search">
    <van-cell title="< 返回" arrow-direction="none" is-link to="/" />
    <van-search v-model="value" placeholder="点击前往搜索" @search="onSearch" />
    <van-cell title="历史记录" value="清空历史记录" @click="empty" />
    <van-card
      v-for="item in search"
      :key="item.id"
      :price="item.retailPrice"
      :title="item.name"
      :thumb="item.picUrl"
      @click="clickSearch(item.id)"
    />
    <van-divider dashed>没有更多了</van-divider>
  </div>
</template>

<script>
import request from '../../utils/request'
export default {
  name: 'search',
  components: {},
  data () {
    return {
      value: '',
      search: ''
    }
  },
  // 计算属性
  computed: {},
  watch: {},
  mounted () {},
  methods: {
    onSearch () {
      request('goods/list', { params: { keyword: this.value } }).then(res => {
        const { data } = res.data
        this.search = data.list
        // console.log(data)
      })
    },
    empty () {
      this.search = ''
    },
    clickSearch (id) {
      this.$router.push('/sonFirstPublish?id=' + id)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
